#! /usr/bin/env
# coding = uft-8

class Solution(object):
    def threeSum(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        nums.sort()
        result = []
        for i in range(len(nums)):
            if i > 0 and nums[i] == nums[i - 1]:
                continue
            j = i + 1
            k = len(nums) - 1
            while j < k:
                sum = nums[i] + nums[j] + nums[k]
                if k != len(nums) -1 and nums[k] == nums[k + 1]:
                    k -= 1
                    continue
                if j > i + 1 and nums[j] == nums[j - 1]:
                    j += 1
                    continue
                if  sum > 0:
                    k -= 1
                elif sum < 0:
                    j += 1
                else:
                    result.append([nums[i], nums[j], nums[k]])
                    k -= 1
                    j += 1
        return result

s = Solution()
print(s.threeSum([0,0,0,0]))

